package com.sky.controller.admin;

import com.github.pagehelper.Page;
import com.sky.dto.CategoryDTO;
import com.sky.dto.CategoryPageQueryDTO;
import com.sky.entity.Category;
import com.sky.result.Result;
import com.sky.service.CategoryService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/admin/category")
public class CategoryController {
    @Autowired
    CategoryService categoryService;
    @PostMapping
    @ApiOperation(value = "添加分类")
    public Result insert(@RequestBody CategoryDTO categoryDTO){
        categoryService.insert(categoryDTO);
        return Result.success();
    }
    @GetMapping("/page")
    @ApiOperation(value = "分页查询")
    public Result select(CategoryPageQueryDTO categoryPageQueryDTO){
        return Result.success(categoryService.select(categoryPageQueryDTO));
    }
    @DeleteMapping
    @ApiOperation(value = "删除分类")
    public Result delete(Integer id){
          categoryService.delete(id);
        return Result.success();
    }
    @PutMapping
    @ApiOperation(value = "修改分类")
    public Result update(@RequestBody CategoryDTO categoryDTO){
        categoryService.update(categoryDTO);
        return Result.success();
    }
    @PostMapping("/status/{status}")
    @ApiOperation(value = "启禁用分类")
    public Result startOrStop(@PathVariable Integer status,Long id){
        categoryService.startOrStop(status,id);
        return Result.success();
    }
    @GetMapping("/list")
    @ApiOperation(value = "启禁用分类")
    public Result startOrStop(Integer type){
        Page<Category> byType = categoryService.findByType(type);
        return Result.success(byType);
    }
}
